﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommunicatorAPI;
using System.Collections;
using System.Runtime.InteropServices;
using Extensil.Common;

namespace Vibz.TeamAssignment
{
    public class ConversationProcessor
    {
        public static void StartConversation(string domain, List<string> users, string subject)
        {
            ArrayList contactArray = new ArrayList();
            foreach(string user in users)
            contactArray.Add(user + "@" + domain);

            object[] sipUris = new object[contactArray.Count];
            int currentObject = 0;

            foreach(object contactObject in contactArray)
            {
                sipUris[currentObject] = contactObject;
                currentObject++;
            }

            long windowHandle;
            CommunicatorAPI.Messenger communicator = new CommunicatorAPI.Messenger();
            CommunicatorAPI.IMessengerAdvanced msgrAdv = communicator as CommunicatorAPI.IMessengerAdvanced;
            if(msgrAdv != null)
            {
                try
                {
                    object obj = msgrAdv.StartConversation(
                               CONVERSATION_TYPE.CONVERSATION_TYPE_IM,
                               sipUris, // object array of signin names
                               null, subject,"1",null);
                    windowHandle = long.Parse(obj.ToString());
                }
                catch(COMException ex)
                {
                    AlertBox.ShowDialog("Could not start the instant messaging. Error code:" + ex.ErrorCode.ToString());
                }
            }
        }
    }
}
